<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:t="http://myfaces.apache.org/tomahawk"
      xmlns:f="http://java.sun.com/jsf/core">

     <ui:composition template="./WEB-INF/Templates/templateProjeto.xhtml">
        <ui:define name="titulo">Consulta de Prefeituras</ui:define>
        <ui:define name="javascript">
            function controlaRadio(){
                var campo1 = document.getElementById("form:codCNPJ");
                var campo2 = document.getElementById("form:UF");
 

                if(document.getElementById("form:radio0").checked){
                    campo1.disabled=false;
                    campo2.disabled=true;
                 }
                 if(document.getElementById("form:radio1").checked){
                    campo1.disabled=true;
                    campo2.disabled=false;
                 }
            }

            function disable(){
                    document.getElementById("form:codCNPJ").disabled=true;
                    document.getElementById("form:UF").disabled=true;
            }
        </ui:define>
        <ui:define name="tituloH1">Consulta Prefeituras</ui:define>
        <ui:define name="pagLinda">
            <h1>Selecione os filtros para sua pesquisa</h1>
            <h:messages layout="list" style="color: darkred"/>
            <h:form id="form">
                <br/>
                <h:panelGrid columns="1" id="painel">
                    <h:panelGroup >
                        <t:selectOneRadio id="filtro" layout="spread" value="#{managedPrefeitura.numRadioPesquisa}" onchange="controlaRadio()">
                                <f:selectItem itemLabel="Por CNPJ" itemValue="cod" />
                                <f:selectItem itemLabel="Por Unidade Federativa" itemValue="uf"/>
                        </t:selectOneRadio>

                        
                    <t:radio for="filtro" index="0" id="radio0" />
                    </h:panelGroup>
                    <h:panelGroup>
                 <!---->                      <!--Há 22 espaços invisiveis (alt+255) entre estes comentarios-->
                        <h:outputLabel value="CNPJ da prefeitura"/>
                        <h:inputText id="codCNPJ" value="#{managedPrefeitura.prefeitura.cnpj}" label="Cod. CNPJ">
                            <f:validateRequired/>
                            <f:validator validatorId="validatorCnpj"/>
                        </h:inputText>
                    </h:panelGroup>


                    <t:radio for="filtro" index="1" id="radio1"/>
                    
                    <h:panelGroup>
                        <!---->                      <!--Há 22 espaços invisiveis (alt+255) entre estes comentarios-->
                        <h:selectOneMenu id="UF" value="#{managedPrefeitura.prefeitura.uf}">
                             <f:selectItem itemLabel="AC" itemValue="AC" />
                             <f:selectItem itemLabel="AL" itemValue="AL" />
                             <f:selectItem itemLabel="AP" itemValue="AP" />
                             <f:selectItem itemLabel="AM" itemValue="AM" />
                             <f:selectItem itemLabel="BA" itemValue="BA" />
                             <f:selectItem itemLabel="CE" itemValue="CE" />
                             <f:selectItem itemLabel="DF" itemValue="DF" />
                             <f:selectItem itemLabel="ES" itemValue="ES" />
                             <f:selectItem itemLabel="GO" itemValue="GO" />
                             <f:selectItem itemLabel="MA" itemValue="MA" />
                             <f:selectItem itemLabel="MG" itemValue="MG" />
                             <f:selectItem itemLabel="MS" itemValue="MS" />
                             <f:selectItem itemLabel="MT" itemValue="MT" />
                             <f:selectItem itemLabel="PA" itemValue="PA" />
                             <f:selectItem itemLabel="PB" itemValue="PB" />
                             <f:selectItem itemLabel="PE" itemValue="PE" />
                             <f:selectItem itemLabel="PI" itemValue="PI" />
                             <f:selectItem itemLabel="PR" itemValue="PR" />
                             <f:selectItem itemLabel="RJ" itemValue="RJ" />
                             <f:selectItem itemLabel="RN" itemValue="RN" />
                             <f:selectItem itemLabel="RO" itemValue="RO" />
                             <f:selectItem itemLabel="RR" itemValue="RR" />
                             <f:selectItem itemLabel="RS" itemValue="RS" />
                             <f:selectItem itemLabel="SC" itemValue="SC" />
                             <f:selectItem itemLabel="SE" itemValue="SE" />
                             <f:selectItem itemLabel="SP" itemValue="SP" />
                             <f:selectItem itemLabel="TO" itemValue="TO" />
                        </h:selectOneMenu>
                    </h:panelGroup>
                </h:panelGrid>
                <br/>
                <h:commandButton value="pesquisar" id="botao_em_baixo" action="#{managedPrefeitura.procurar}"/>
               <h:commandButton value="Pesquisar todas prefeituras" action="#{managedPrefeitura.procurarTodos()}" onclick="disable()"/>
                <script>
                    controlaRadio();
                </script>
            </h:form>
        </ui:define>
     </ui:composition>
    
</html>
